//
//  MenuCollectionViewCell_OnePage.m
//  MKUITestApp
//
//  Created by 苏尚进 on 2020/10/6.
//  Copyright © 2020 moon. All rights reserved.
//

#import "MenuCollectionViewCell_OnePage.h"
#import "Menu.h"
@implementation MenuCollectionViewCell_OnePage
- (id)initWithFrame:(CGRect)frame{
    if (self=[super initWithFrame:frame]) {
        self.menuButton = [[MKUIFlowLayoutButton alloc] initWithContentStyle:MKUIFlowLayoutButtonContentStyleHorizontal];
        self.menuButton.contentInsets = MKUIEdgeInsetsMakeSameEdge(5);
        [self.menuButton setTitleColor:[UIColor systemBlueColor] forState:UIControlStateNormal];
        self.menuButton.titleLabel.numberOfLines = 3;
        self.menuButton.interitemSpacing = 10;
        [self.menuButton addTarget:self action:@selector(_menuButtonDidTap:) forControlEvents:UIControlEventTouchUpInside];
        self.menuButton.userInteractionEnabled = NO;
        [self.contentView addSubview:self.menuButton];
    }
    return self;
}
- (void)_menuButtonDidTap:(id)sender{
    [self.collectionCellModel didClickSelf];
}
- (void)layoutSubviews{
    [super layoutSubviews];
    CGRect bounds = self.contentView.bounds;
    self.menuButton.frame = bounds;
}
- (void)setCollectionCellModel:(__kindof MKUICollectionViewCellModel *)collectionCellModel{
    [super setCollectionCellModel:collectionCellModel];
    Menu *menu = self.collectionCellModel.modelValue;
    if(!menu){
        return;
    }
    [self.menuButton setImage:menu.icon forState:UIControlStateNormal];
    [self.menuButton setTitle:[NSString stringWithFormat:@"%@(%@-%@)",menu.title,@(self.collectionCellModel.indexPathInModel.section),@(self.collectionCellModel.indexPathInModel.item)] forState:UIControlStateNormal];
}
@end

@implementation MenuCollectionViewCell_OnePageLeft
- (id)initWithFrame:(CGRect)frame{
    if (self=[super initWithFrame:frame]) {
        self.menuButton.layoutHorizontalAlignment = MKUILayoutConstraintHorizontalAlignmentLeft;
    }
    return self;
}


@end
